#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
异常处理模块

集中定义应用中所有的异常类型，便于统一处理和管理
"""

class AppException(Exception):
    """应用基础异常类"""
    def __init__(self, message="应用发生错误", code=-1):
        self.message = message
        self.code = code
        super().__init__(self.message)


class AuthException(AppException):
    """认证相关异常"""
    def __init__(self, message="认证失败", code=401):
        super().__init__(message, code)


class PermissionException(AppException):
    """权限相关异常"""
    def __init__(self, message="权限不足", code=403):
        super().__init__(message, code)


class ResourceNotFoundException(AppException):
    """资源不存在异常"""
    def __init__(self, message="请求的资源不存在", code=404):
        super().__init__(message, code)


class ValidationException(AppException):
    """数据验证异常"""
    def __init__(self, message="数据验证失败", code=400, errors=None):
        self.errors = errors or {}
        super().__init__(message, code)


class DataAccessException(AppException):
    """数据访问异常"""
    def __init__(self, message="数据库操作失败", code=500):
        super().__init__(message, code)


class BusinessException(AppException):
    """业务逻辑异常"""
    def __init__(self, message="业务处理失败", code=422):
        super().__init__(message, code) 